package com.xinxin.leetcode.problem367;

/**
 * @author ShiXinXin
 * @date 2019-08-30 1:09
 */
class Solution {
    public boolean isPerfectSquare(int num) {
        if (num == 1) {
            return true;
        }
        int start = 1, end = Math.min(46340, num / 2);
        int mid;
        while (start <= end) {
            mid = start + (end - start) / 2;
            if (mid * mid == num) {
                return true;
            }
            if (mid * mid < num) {
                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
//        for (int i = 1; i < 808202; i++) {
//            if (solution.isPerfectSquare(i)) {
        System.out.println(solution.isPerfectSquare(808201));
//            }
//        }
    }
}
